package com.java.comprehensive.design.behavioral_model.memento_pattern.black_box;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 发起人角色
 * <p>
 * 游戏角色类
 */
@Data
public class GameRole {
    //角色属性
    private Integer vit;
    //角色属性
    private Integer atk;
    //角色属性
    private Integer def;

    //初始化内部状态
    public void initState() {
        this.vit = 100;
        this.atk = 100;
        this.def = 100;
    }

    public void fight() {
        this.vit = 0;
        this.atk = 0;
        this.def = 0;
    }

    public RoleStateMemento saveState() {
        return new RoleStateMemento(vit, atk, def);
    }

    //恢复角色状态
    public void recoverState(Memento memento) {
        RoleStateMemento roleStateMemento = (RoleStateMemento) memento;
        this.vit = roleStateMemento.getVit();
        this.atk = roleStateMemento.getAtk();
        this.def = roleStateMemento.getDef();
    }

    public void stateDisplay() {
        System.out.println("攻击力：" + vit);
        System.out.println("生命值：" + atk);
        System.out.println("防御力：" + def);
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    private static class RoleStateMemento implements Memento {

        //角色属性
        private Integer vit;
        //角色属性
        private Integer atk;
        //角色属性
        private Integer def;
    }
}
